package org.itzixi.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.itzixi.base.BaseInfoProperties;
import org.itzixi.grace.result.GraceJSONResult;
import org.itzixi.pojo.FriendCircleLiked;
import org.itzixi.pojo.bo.CommentBO;
import org.itzixi.pojo.bo.FriendCircleBO;
import org.itzixi.pojo.vo.CommentVO;
import org.itzixi.pojo.vo.FriendCircleVO;
import org.itzixi.service.CommentService;
import org.itzixi.service.FriendCircleService;
import org.itzixi.utils.PagedGridResult;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("comment")
public class CommentController extends BaseInfoProperties {
    @Resource
    private CommentService commentService;


    @PostMapping("create")
    public GraceJSONResult create(@RequestBody CommentBO commentBO,
                                   HttpServletRequest request) {

        CommentVO commentVO = commentService.createComment(commentBO);
        return GraceJSONResult.ok(commentVO);
    }

///comment/query?friendCircleId=
    @PostMapping("query")
    public GraceJSONResult query(String friendCircleId) {
        return GraceJSONResult.ok(commentService.queryAll(friendCircleId));
    }

    ///comment/delete?commentUserId=" + commentUserId + "&commentId=" + commentId + "&friendCircleId=" + friendCircleId,

    @PostMapping("delete")
    public GraceJSONResult delete(String commentUserId,
                                  String commentId,
                                  String friendCircleId) {
        if(StringUtils.isBlank(commentUserId) || StringUtils.isBlank(commentId) || StringUtils.isBlank(friendCircleId)){
            return GraceJSONResult.error();
        }
        commentService.deleteComment(commentId, commentUserId, friendCircleId);
        return GraceJSONResult.ok();
    }

}
